package cn.lcsjsxy.yxc.objectoriented.多态性;
//多态性的使用举例一：
public class AnimalTest {
    public static void main(String[] args) {
        AnimalTest animalTest=new AnimalTest();
        animalTest.func(new Dog());  //Animal animal=new Dog();
        animalTest.func(new Cat());  //Animal animal=new Cat();
    }

    public void func(Animal animal){
        animal.eat();
        animal.shout();
    }
}

class Animal {
    public void eat() {
        System.out.println("动物，进食");
    }

    public void shout() {
        System.out.println("动物，叫");
    }
}

class Dog extends Animal{
    public void eat(){
        System.out.println("狗，进食");
    }

    public void shout(){
        System.out.println("狗，叫");
    }
}

class Cat extends Animal{
    public void eat(){
        System.out.println("猫吃鱼");
    }

    public void shout(){
        System.out.println("猫喵喵");
    }
}

